
package com.amigo.online.consumer.merchant.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseConsumerController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.param.dto.merchant.CommentReplyDto;
import com.amigo.online.common.param.dto.merchant.EditBasicMerchantDto;
import com.amigo.online.common.param.dto.merchant.MerchantApplyDto;
import com.amigo.online.common.param.dto.merchant.MerchantAvatarDto;
import com.amigo.online.common.param.dto.merchant.MerchantCommentDto;
import com.amigo.online.common.param.dto.merchant.MerchantEnvironmentDto;
import com.amigo.online.common.util.CommonValidator;
import com.amigo.online.consumer.merchant.exception.GoodsException;
import com.amigo.online.consumer.merchant.service.MerchantOwnerService;

/**
<code>MerchantOwnerController.java</code>
<p>
	: 商家拥有者controllers
</p>
<p>
	@company Amigo
	@author LuChen
	@time 2018年12月21日 上午10:30:26
	@version 1.0 
	@lastUpdate 无
</p>
*/
@RestController
@RequestMapping(value = "/merOwner", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MerchantOwnerController extends BaseConsumerController {
	
	
	@Autowired
	private MerchantOwnerService merchantOwnerService;
	
	
	/**
	 * 获取商家评论列表
	 * @return
	 */
	@PostMapping("/getMerchantComment")
	public ResponseEntity<Response> getMerchantComment(@RequestBody MerchantCommentDto dto){
		if (!CommonValidator.validate(dto)) {
			throw new GoodsException(StatusCode.BAD_REQUEST);
		}
		return merchantOwnerService.getMerchantComment(dto);
	}
	
	
	/**
	 * 获取商家管理成员列表（不包含店长）
	 * @return
	 */
	@GetMapping("/getMerchantManagerList")
	public ResponseEntity<Response> getManagerList(@RequestParam("merchantId") Long merchantId){
		return merchantOwnerService.getMerchantComment(merchantId);
	}
	
	@GetMapping("/addManager")
	public ResponseEntity<Response> addManager(@RequestParam("merchantId") Long merchantId,@RequestParam("userId") Long userId){
		return merchantOwnerService.addManager(merchantId,userId);
	}
	
	@DeleteMapping("/removeManager")
	public ResponseEntity<Response> removeManager(@RequestParam("merchantId") Long merchantId,@RequestParam("userId") Long userId){
		return merchantOwnerService.removeManager(merchantId,userId);

	}
	
	@PostMapping("/replyComment")
	public ResponseEntity<Response> replyComment(@RequestBody CommentReplyDto dto){
		if (!CommonValidator.validate(dto)) {
			throw new GoodsException(StatusCode.BAD_REQUEST);
		}
		return merchantOwnerService.replyComment(dto);
	}
	
	/**
	 * 提交商户资料申请开通
	 * @return
	 */
	@PostMapping("/applyOpen")
	public ResponseEntity<Response> applyOpenMerchant(@RequestBody @Validated MerchantApplyDto dto){
		return merchantOwnerService.applyOpenMerchant(dto);
	}
	/**
	 * 修改店铺头像
	 * @return
	 */
	@PostMapping("/merchant/avatar")
	public ResponseEntity<Response> editMerchant(@RequestBody MerchantAvatarDto dto){
		return merchantOwnerService.editMerchantAvatar(dto);
	}
	/**
	 * 添加或修改店铺环境
	 * @return
	 */
	@PostMapping("/merchant/environment")
	public ResponseEntity<Response> merchantEnvironment(@RequestBody MerchantEnvironmentDto dto){
		return merchantOwnerService.merchantEnvironment(dto);
	}	
	/**
	 * 修改店铺营业时间、服务电话、门店地址
	 * @return
	 */
	@PostMapping("/merchant/basic")
	public ResponseEntity<Response> editBasicMerchant(@RequestBody EditBasicMerchantDto dto){
		return merchantOwnerService.editBasicMerchant(dto);
	}
	
	
	/**
	 * 获得用户店铺状态
	 * 
	 * @return 0-初始用户 1-审核失败 2-审核中 3-已经是商家 4-该用户是管理员
	 */
	@GetMapping("/getUserMerchantStatus")
	public ResponseEntity<Response> getUserMerchantInfo() {
		return merchantOwnerService.getUserMerchantInfo();
	}
	
	/**
	 * 根据店铺状态获取店铺信息
	 * 
	 * @return 0-初始用户 1-审核失败 2-审核中 3-已经是商家 4-该用户是管理员
	 */
	@GetMapping("/getUserMerchantInfo/{status}")
	public ResponseEntity<Response> getUserMerchantStatus(@PathVariable("status") Integer status) {
		return merchantOwnerService.getUserMerchantStatus(status);
	}
	
	/**
	 * 获得品类列表
	 * @return
	 */
	@GetMapping("/categoryList")
	public ResponseEntity<Response> getCategoryList(@RequestParam(value = "type", required = false) Integer type) {
		return merchantOwnerService.getCategoryList(type);
	}
	
	/**
	 * 根据店铺id 获得店铺的详细信息
	 * @return
	 */
	@GetMapping("/getMerchantManagerInfo/{id}")
	public ResponseEntity<Response> getMerchantDetailInfo(@PathVariable("id") Long id){
		return merchantOwnerService.getMerchantDetailInfo(id);
	}
	
	/**
	 * 商户端获得商品信息
	 * 
	 * @return
	 */
	@GetMapping("/merchantGoods")
	public ResponseEntity<Response> getMerchantGoods(@RequestParam(name="merchantId") Long merchantId, @RequestParam(name="status",required=false) Integer status,
			@RequestParam(name="categoryId",required=false) Long categoryId,@RequestParam Integer page,@RequestParam Integer size) {
		return merchantOwnerService.getMerchantGoods(merchantId, status, categoryId, page, size);
	}
	
	
	
	@DeleteMapping("/quitManager")
	public ResponseEntity<Response> quitManager(@RequestParam("merchantId") Long merchantId){
		return merchantOwnerService.quitManager(merchantId);
	}
	
	
	
	
	
	
	
	
}

